package com.telit.firecommand.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.common.entity.DataReturn;
import com.telit.common.entity.PageData;
import com.telit.firecommand.entity.CommRoamingLine;
import com.telit.firecommand.service.RoamingLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther amy
 * @Describe 漫游路线控制层
 */
@RestController
@Api(tags="漫游路线控制层")
@RequestMapping("/roaming-line")
public class RoamingLineController {

    @Autowired
    private RoamingLineService roamingLineService;

    @GetMapping(value="/listByPage",produces = "application/json;charset=UTF-8")
    @ApiOperation("分页查询")
    public DataReturn listByPage(@RequestParam(defaultValue = "1") Integer current,
                                 @RequestParam(defaultValue = "10") Integer size,
                                 @ModelAttribute CommRoamingLine commRoamingLine){
        IPage<CommRoamingLine> page = roamingLineService.listByPage(current,size,commRoamingLine);
        return DataReturn.ok(new PageData<>((int)page.getTotal(),current,size,page.getRecords()));
    }

    @GetMapping(value="/listNoPage",produces = "application/json;charset=UTF-8")
    @ApiOperation("无分页查询")
    public DataReturn listNoPage(@ModelAttribute CommRoamingLine commRoamingLine){
        return DataReturn.ok(roamingLineService.listNoPage(commRoamingLine));
    }

    @PostMapping(value="/add",produces = "application/json;charset=UTF-8")
    @ApiOperation("新增")
    public DataReturn add(@RequestBody @Validated CommRoamingLine commRoamingLine){
        roamingLineService.add(commRoamingLine);
        return DataReturn.ok();
    }

    @PutMapping(value="/update/{id}",produces = "application/json;charset=UTF-8")
    @ApiOperation("修改")
    public DataReturn update(@PathVariable("id") Long id,
                             @RequestBody @Validated CommRoamingLine commRoamingLine){
        commRoamingLine.setId(id);
        roamingLineService.update(commRoamingLine);
        return DataReturn.ok();
    }

    @GetMapping(value="/detail/{id}",produces = "application/json;charset=UTF-8")
    @ApiOperation("详情")
    public DataReturn detail(@PathVariable("id")Long id){
        return DataReturn.ok(roamingLineService.detail(id));
    }

    @DeleteMapping(value = "/deleteBatch",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "批量删除")
    public DataReturn deleteBatch(@RequestParam("ids") List<Long> ids){
        roamingLineService.deleteBatch(ids);
        return DataReturn.ok();
    }
}
